home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0069_Secure File Wiping.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  88 lines

  1. {
  2. Although, I can not gaurentee this is correct, but it WILL stop Undel
  3. from PCTools, Undel from nortons, and undelete from dos. (tested) Although
  4. I don't have the time to play around with a sector editor:
  5. }
  6.  
  7. {$A+,B-,D+,E+,F-,G-,I-,L+,N-,O-,P-,Q-,R-,S+,T-,V+,X+}
  8. {$M 16384,0,655360}
  9. Uses crt,dos;
  10. Const
  11.   Product = 'WipeFile';
  12.   Version = '1.00a';
  13.   Release = 'Gamma';
  14.   Author  = 'John Stephenson';
  15.  
  16. Procedure WipeFile(fn: string);
  17. Var
  18.   size,
  19.   total: longint;
  20.   loop,towrite,numwritten: word;
  21.   f: file;
  22.   buffer: array[1..1024] of byte;
  23. begin
  24.   assign(f,fn);
  25.   setfattr(f,0);
  26.   if doserror = 0 then begin
  27.     { DOS will normally keep the rest of the file name, and just truncate
  28.       it with a null. But when the full filename is renamed then that can't
  29.       be done. Then it renames it to ~ so that undelete will just show
  30.       a question mark, and same with a sector editor on the hd }
  31.     rename(f,'~~~~~~~~.~~~');
  32.     rename(f,'~');
  33.  
  34.     { Randomize a buffer for later use when we erase the file }
  35.     for loop := 1 to sizeof(buffer) do buffer[loop] := random(256);
  36.  
  37.     { Then we must completely rewrite the file, starting from byte one
  38.       to the filesize, completely erasing all sector data. Very easily
  39.       done, using a random buffer to write with. }
  40.     reset(f,1);
  41.     size := filesize(f);
  42.     total := 0;
  43.     repeat
  44.       { Figure out how much to write }
  45.       towrite := sizeof(buffer);
  46.       if towrite+total > size then towrite := size - total;
  47.  
  48.       blockwrite(f,buffer,towrite,numwritten);
  49.       inc(total,numwritten);
  50.     until total = size;
  51.  
  52.     { Now we seek to the first byte of the file, and truncate it there,
  53.       leaving it a measly 0 bytes }
  54.     Seek(f,0);
  55.     Truncate(f);
  56.  
  57.     { Now we will close up the file, and delete it }
  58.     close(f);
  59.     erase(f);
  60.   end;
  61. end;
  62.  
  63. var
  64.   loop: byte;
  65.   fn: pathstr;
  66. begin
  67.   if paramcount = 0 then begin
  68.     textattr := lightcyan;
  69.     writeln(product+' v'+version+' '+release+' by '+author+#10);
  70.     textattr := lightgray;
  71.     writeln('Completely erases file contents, and filename from FAT and');
  72.     writeln('from the actual disk. Very throughly done!'#10);
  73.     writeln('Summary of action: ■ Un-attributes file.');
  74.     writeln('                   ■ Renames FAT file name.');
  75.     writeln('                   ■ Rewrites file contents with a random buffer');
  76.     writeln('                   ■ Truncates file to 0 bytes.');
  77.     writeln('                   ■ Erases file.');
  78.     halt(1);
  79.   end;
  80.   randomize;
  81.   for loop := 1 to paramcount do begin
  82.     Fn := paramstr(loop);
  83.     write('Wiping: ',fn,'...');
  84.     wipefile(fn);
  85.     writeln(' Done!');
  86.   end;
  87. end.
  88.